<template>
  <div class="list">
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="id" label="ID">
      </el-table-column>
      <el-table-column prop="name" label="名称">
      </el-table-column>
      <el-table-column prop="issue" label="问题类型">
      </el-table-column>
      <el-table-column prop="email" label="电子邮件">
      </el-table-column>
      <el-table-column prop="account" label="账户">
      </el-table-column>
      <el-table-column prop="theme" label="主题">
      </el-table-column>
      <el-table-column prop="" label="内容">
        <template slot-scope="{row}">
          <el-button type="text" @click="openContent(row)">查看</el-button>
        </template>
      </el-table-column>

      <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <!--  <el-button @click="handleClick(scope.row)" type="text" >查看</el-button> -->
          <el-button size="mini" type="danger" @click="toDel(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="prev, pager, next" :total="total" :page-size="size" @prev-click="prev()"
      @next-click="next()" @current-change="currentchange" style="margin-top: 20px;">
    </el-pagination>

    <el-dialog title="反馈内容" :visible.sync="dialogVisible" width="30%">
      <span>{{content}}</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {
    ajaxPost
  } from "@/api/ajax"
  export default {
    name: "list",
    data() {
      return {
        tableData: [],
        page: 1,
        size: 15,
        total: 0,
        current_page: 1,
        dialogVisible: false,
        content: ""
      };
    },
    created() {
      this.getList();
    },
    methods: {
      getList() {
        let data = {
          page: this.page,
          size: this.size,
        };
        ajaxPost('feedback/list', data).then(res => {
          if (res.code == 0) {
            this.tableData = res.data.data;
            this.total = res.data.total;
            this.current_page = res.data.current_page;
          }
        })
      },
      openContent(row) {
        this.content = row.content;
        this.dialogVisible = true;

      },
      prev() {
        this.page -= 1;
        this.getList();
      },
      next() {
        this.page += 1;
        this.getList();
      },
      currentchange(value) {
        this.page = value;
        this.getList();
      },
      toDel(id) {
        this.$confirm('确认删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          ajaxPost('feedback/delete', {
            id: id
          }).then(res => {
            if (res.code == 0) {
              this.$message({
                type: 'success',
                message: '删除成功!',
              });
              this.getList();
            } else {
              this.$message({
                type: 'error',
                message: '删除失败!'
              });
            }
          })

        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      }
    },
  }
</script>

<style lang="scss">
  .list {
    padding: 20px;
    box-sizing: border-box;

    .search-input {
      width: 150px;
    }

    .list-page {
      margin-top: 20px;
    }
  }
</style>
